window.onkeypress = function(e) {
    if (e.keyCode == 27)
        window.close();
}
var prefs = Components.classes['@mozilla.org/preferences-service;1']
    .getService(Components.interfaces.nsIPrefService)
    .getBranch('extensions.thytube.');

window.onload = function(e) {
    links = document.getElementsByTagNameNS('http://www.w3.org/1999/xhtml', 'a');
    for (var i = 0; (link = links[i]); i++)
        link.onclick = function(e) {
            window.close();
            window.opener.openURL(e.target.getAttribute('href'));
        }
    document.getElementById('close').onclick = function() {
        window.close();
    }
    var player = document.getElementById('thytube-player'),
        items = player.getElementsByTagName('menuitem');
    for (var i = 0; (item = items[i]); i++) {
            item.setAttribute('oncommand', 'prefs.setIntPref("player", this.value);');
    }
}
